/**
 * Created by sunyongqi on 2017/7/17.
 */
var getUserMedia;
var onpenCamera = function () {
    getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia)
    getUserMedia.call(navigator, {
        video: true,
        audio: false
    }, function(localMediaStream) {
        console.log(localMediaStream);
        var video = document.getElementById('video');
        var url = window.URL.createObjectURL(localMediaStream);
        console.log(url);
        video.src = url;
        video.onloadedmetadata = function(e) {
            console.log("Label: " + localMediaStream.label);
            console.log("AudioTracks" , localMediaStream.getAudioTracks());
            console.log("VideoTracks" , localMediaStream.getVideoTracks());
        };
    }, function(e) {
        console.log('Reeeejected!', e);
    });
}
var closeComera = function () {
    getUserMedia = undefined;
}
var videoButtonClick = function(){
    var video = document.getElementById('video');
    if(video.getAttribute('data-paused') == 'true'){
        onpenCamera();
        video.play();
        video.setAttribute('data-paused','false');
    }else{
        closeComera();
        video.pause();
        video.setAttribute('data-paused','true');
    }
}